package com.lsy.on_line.zaixian.controller;

import com.lsy.on_line.zaixian.model.entity.Banner;
import com.lsy.on_line.zaixian.model.entity.Video;
import com.lsy.on_line.zaixian.service.IVideoService;
import com.lsy.on_line.zaixian.utils.JsonData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author ShiYuan
 * @since 2022-07-24
 */
@RestController
@RequestMapping("/api/v1/pub/zaixian/video")
public class VideoController {

    @Autowired
    private IVideoService iVideoService;

    /**
     * 首页轮播图列表
     */
    @GetMapping("bannerList")
    public JsonData indexBanner(){
        List<Banner> bannerList  = iVideoService.bannerList();
        return JsonData.buildSuccess(bannerList);
    }

    /**
     * 查询视频详情，包括章节，集数等全部信息
     * @param videoId
     * @return
     */
    @GetMapping("/find_detail_by_id")
    public JsonData findDetailById(@RequestParam(value = "video_id",required = true)int videoId){
        Video video = iVideoService.findDetailById(videoId);
        return JsonData.buildSuccess(video);
    }

    /**
     * 全部视频列表
     * @return
     */
    @RequestMapping("/List")
    public Object videoList(){
        List<Video> videoList = iVideoService.videoList();
        if (videoList == null){
            return new JsonData(-1,"请求失败",null);
        }
        return JsonData.buildSuccess(videoList);
    }

}
